package com.ruoyi.filemanager.command;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.filemanager.constant.ElFinderConstants;
import com.ruoyi.filemanager.core.Target;
import com.ruoyi.filemanager.core.Volume;
import com.ruoyi.filemanager.service.ElfinderStorage;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class SizeCommand extends AbstractJsonCommand implements ElfinderCommand
{
    @Override
    protected void execute(ElfinderStorage elfinderStorage, HttpServletRequest request, JSONObject json)
            throws Exception
    {
        final String[] targets = request.getParameterValues(ElFinderConstants.ELFINDER_PARAMETER_TARGETS);
        List<Target> targetList = findTargets(elfinderStorage, targets);

        long size = 0;
        for (Target target : targetList)
        {
            Volume volume = target.getVolume();
            size += volume.getSize(target);
        }
        json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_SIZE, size);
    }
}
